package com.simpleim.starter.sender;

import com.simpleim.im.common.bean.ChatMsg;
import com.simpleim.im.common.bean.msg.ProtoMsg;
import com.simpleim.starter.protoBuilder.ChatMsgBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

/**
 * 聊天发送器
 */
@Service
public class ChatSender extends BaseSender{

    private static final Logger LOGGER = LoggerFactory.getLogger(ChatSender.class);

    public void sendChatMsg(String touid, String content) {
        LOGGER.info("发送消息 startConnectServer");
        ChatMsg chatMsg = new ChatMsg(getUser());
        chatMsg.setContent(content);
        chatMsg.setMsgType(ChatMsg.MSGTYPE.TEXT);
        chatMsg.setTo(touid);
        chatMsg.setMsgId(System.currentTimeMillis());
        ProtoMsg.Message message = ChatMsgBuilder.buildChartMsg(chatMsg, getUser(), getSession());
        super.sendMsg(message);
    }

    @Override
    public void sendSuccess(ProtoMsg.Message message) {
        LOGGER.info("发送消息：{}成功", message.getMessageRequest().getContent());
    }

    @Override
    public void sendFail(ProtoMsg.Message message) {
        LOGGER.info("发送消息：{}失败", message.getMessageRequest().getContent());
    }
}
